<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    ul,
    ol {
        list-style: none;
    }

    ol {
        position: fixed;
        top: 150px;
        left: 100px;
    }

    ol>li {
        width: 50px;
        height: 50px;
        border: 1px solid #000000;
        text-align: center;
        line-height: 50px;
        margin-top: -1px;
    }

    html,
    body {
        width: 100%;
        height: 100%;
    }

    ul {
        width: 100%;
        height: 100%;
    }

    ul>li {
        width: 100%;
        height: 100%;
    }
</style>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>

    <ol>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ol>
</body>
<script>
    window.onload = function () {
        var ols = document.querySelectorAll('ol>li')
        var uls = document.querySelectorAll('ul>li')
        var colos = ['red', 'orange', 'yellow', 'green', 'blue']
        var target = 0
        var leader = 0
        var timer = null

        ols.forEach((item, index) => {
            item.style.backgroundColor = colos[index]
            uls[index].style.backgroundColor = colos[index]

            ols[index].onclick = function () {
                clearInterval(timer)
                target = uls[index].offsetTop
                timer = setInterval(() => {
                    leader = leader + (target - leader) / 10
                    //scrollTo(参数1,参数2)
                    //参数1为X方向 滚动的距离
                    //参数2 为Y方向 滚动的距离
                    window.scrollTo(0, leader)
                }, 30)
            }
        })

    }
</script>

</html>